#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QPainter>
#include <QDebug>
#include <QPoint>
#include <QMessageBox>
#include <QtMath>
#include <QToolBar>



QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow                                                               //主窗口
{
    Q_OBJECT

public:                                                                         //斜着行走
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void paintEvent(QPaintEvent *);                                                                 //绘画事件
    void mousePressEvent(QMouseEvent *event);                                                       //鼠标按压事件
    void closeEvent(QCloseEvent *event);                                                            //窗口关闭事件

private slots:

    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

    void on_pushButton_3_clicked();

    void on_pushButton_4_clicked();

private:
    int startX;                                                                                     //绘图开始坐标
    int startY;                                                                                     //绘图结束坐标
    int gridW;                                                                                      //像素宽度坐标
    int gridH;                                                                                      //绘图高度坐标
    int paintX[2];                                                                                  //开始点和结束点横坐标
    int paintY[2];                                                                                  //开始点和结束点纵坐标
    Ui::MainWindow *ui;
};


// FIXME: it is better move following class to a seperate file

class Point                                                                                         //面对点对象类
{
public:
    int x,y;                                                                                        //坐标位置
    int F,G,H;                                                                                      //直接代价和间接代价和总代价
    Point *parent;                                                                                  //点的父坐标 类似与单向链表
    Point(int _x,int _y):x(_x),y(_y),F(0),G(0),H(0),parent(NULL)  //变量初始化
    {
    }
};

class Path_Serch
{
public:

    int calcG(Point * ,Point *);                                                                    //获取直接代价
    int calcH(Point *,Point *);                                                                     //获取间接代价
    int calcF(Point *);                                                                             //获取总接代价

    Point * getLeastFpoint();                                                                       //获取直接代价最小点的指针
    Point * findPath(Point &,Point &,bool);                                                         //寻找路径A*算法的简单实现
    std::list<Point *> GetPath(Point &startPoint,Point &endPoint,bool isIgnoreCorner);              //获取路径用列表存储
    Point *isInList(const std::list<Point *> &list,const Point *point) const;                       //判断是否在开启列表中
    bool isCanreach(const Point *point,const Point *target,bool isIgnoreCorner) const;              //如果点与当前节点重合、超出地图、是障碍物、或者在关闭列表中，返回false
    std::vector<Point *> getSurroundPoints(const Point *point,bool isIgnoreCorner) const;           //获取周围八个点的坐标用vector存储
    std::list<Point *> openList;  //开启列表
    std::list<Point *> closeList; //关闭列表
};
#endif // MAINWINDOW_H
